package com.ticket.sass.admin.dto.input.pricescheme;

import com.ticket.sass.admin.annotation.WeekTimeRange;
import com.ticket.sass.admin.dto.input.WeekTimeInput;
import com.ticket.sass.admin.validator.InEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * @author ywb
 * @date 2024-03-07 10:58
 */
@Data
@ApiModel
@WeekTimeRange
public class PriceSchemeAddInput {
    @NotBlank(message = "标题不能为空")
    @ApiModelProperty(value = "方案名称")
    private String title;
    
    @NotNull(message = "可用日期类型不能为空")
    @InEnum(intValues = {0, 1})
    @ApiModelProperty(value = "生效类型：0 不限 1 指定")
    private Short activateType;
    
    @ApiModelProperty(value = "有效日期开始")
    private LocalDate startDate;
    
    @ApiModelProperty(value = "有效日期结束")
    private LocalDate endDate;
    
    @NotNull(message = "可用时段类型不能为空")
    @InEnum(intValues = {0, 1})
    @ApiModelProperty(value = "可用时段：0 不限制，1 指定范围")
    private Short availablePeriod;
    
    @Valid
    @ApiModelProperty(value = "星期时间数据")
    private List<WeekTimeInput> weekTimes;
    
    @ApiModelProperty(value = "发行价")
    @Valid
    private List<@DecimalMin(value = "0", inclusive = true, message = "售价必须大于等于0") BigDecimal> issuePrices;
    
    @NotNull(message = "售价不能为空")
    @DecimalMin(value = "0", inclusive = true, message = "售价必须大于等于0")
    @ApiModelProperty(value = "售价（不为空则优先级高于所有票价方案）")
    private BigDecimal salePrice;
    
    @ApiModelProperty(value = "影厅ID")
    private List<Long> hallIds;
    
    @ApiModelProperty(value = "影片ID")
    private List<Long> filmIds;
    
    @Valid
    @ApiModelProperty(value = "会员价输入")
    private List<MemberPriceInput> memberPriceInput;
    
    @NotNull(message = "请必须选择启用")
    @ApiModelProperty(value = "是否启用")
    private Boolean enable = Boolean.FALSE;
    
    @ApiModelProperty(value = "核销方式 1 平台核销")
    private Short useMethod;
    
    @ApiModelProperty(value = "")
    private Boolean refund;
    
    @AssertTrue(message = "日期不能为空")
    private boolean isDateRange() {
        // 如果 activateType 为 1（指定日期），则 startDate 和 endDate 都不能为空
        if (activateType != null && activateType == 1) {
            return startDate != null && endDate != null;
        }
        // 其他情况不需要验证
        return true;
    }
}
